package cn.admin.remoting;

public final class ResponseOfRequest {

    private final String remoteIP;
    private final int remotePort;
    private final int errorCode;
    private final String errorMsg;
    private final Object appResponse;
    private final long responseTime;

    public ResponseOfRequest(Object _appResponse, String _clientIP, int _clientPort) {
        this.remoteIP = _clientIP;
        this.remotePort = _clientPort;
        this.errorCode = 0;
        this.errorMsg = "SUCCESS";
        this.appResponse = _appResponse;
        this.responseTime = System.currentTimeMillis();
    }

    public ResponseOfRequest(int _errorCode, String _errorMsg, String _clientIP, int _clientPort) {
        if (0 == _errorCode) {
            throw new IllegalArgumentException();
        } else if (null == _errorMsg) {
            throw new IllegalArgumentException();
        } else {
            this.remoteIP = _clientIP;
            this.remotePort = _clientPort;
            this.errorCode = _errorCode;
            this.errorMsg = _errorMsg;
            this.appResponse = null;
            this.responseTime = System.currentTimeMillis();
        }
    }

    @Override
    public String toString() {
        return "ResponseOfRequest{" +
                "remoteIP='" + remoteIP + '\'' +
                ", remotePort=" + remotePort +
                ", errorCode=" + errorCode +
                ", errorMsg='" + errorMsg + '\'' +
                ", appResponse=" + appResponse +
                ", responseTime=" + responseTime +
                '}';
    }

    public String getRemoteIP() {
        return this.remoteIP;
    }

    public int getRemotePort() {
        return this.remotePort;
    }

    public int getErrorCode() {
        return this.errorCode;
    }

    public String getErrorMsg() {
        return this.errorMsg;
    }

    public Object getAppResponse() {
        return this.appResponse;
    }

    public long getResponseTime() {
        return this.responseTime;
    }

}
